package com.css.fxfzdzzh.modules.basicData.service.impl;

import com.css.fxfzdzzh.modules.basicData.repository.impl.LithologyRepository;
import com.css.fxfzdzzh.modules.basicData.vo.LithologyVO;
import com.css.fxfzdzzh.util.PlatformObjectUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author Dbj
 * @date 2023年03月02日  15:27
 */
@Service
public class LithologyService {

    @Resource
    RedisTemplate redisTemplate;
    @Resource
    LithologyRepository lithologyRepository;
    public Map<String, String> getLithologyMap(){
        Map<String, String> map = (Map<String, String>) redisTemplate.opsForHash().entries("dzdzzhpg:lithology:type");
        if(PlatformObjectUtils.isEmpty(map)){
            List<LithologyVO> voList = lithologyRepository.getLithologyList();
            if(PlatformObjectUtils.isNotEmpty(voList)){
                Map<String, String> collect = voList.stream().collect(Collectors.toMap(LithologyVO::getDslCode, LithologyVO::getPetrlfabricType));
                redisTemplate.opsForHash().putAll("dzdzzhpg:lithology:type",collect);
                return collect;
            }
        }
        return map;
    }
}
